package edu.tongji.libraryapp;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_my_library);

		bindUserInteration();
	}

	private void bindUserInteration() {
		ImageView messageImageView = (ImageView) findViewById(R.id.messageImageView);
		messageImageView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent notificationCenterIntent = new Intent();
				notificationCenterIntent.setClass(MainActivity.this,
						NotificationCenterActivity.class);
				startActivity(notificationCenterIntent);
				overridePendingTransition(R.anim.slide_in_left,
						R.anim.slide_out_left);
			}
		});

		LinearLayout currentBorrowLayout = (LinearLayout) findViewById(R.id.currentBorrowLayout);
		currentBorrowLayout.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				Intent currentBorrowIntent = new Intent();
				currentBorrowIntent.setClass(MainActivity.this,
						CurrentBorrowActivity.class);
				startActivity(currentBorrowIntent);
				overridePendingTransition(R.anim.slide_in_left,
						R.anim.slide_out_left);
			}
		});

		LinearLayout historyBorrowLayout = (LinearLayout) findViewById(R.id.historyBorrowLayout);
		historyBorrowLayout.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				Intent historyBorrowIntent = new Intent();
				historyBorrowIntent.setClass(MainActivity.this,
						HistoryBorrowActivity.class);
				startActivity(historyBorrowIntent);
				overridePendingTransition(R.anim.slide_in_left,
						R.anim.slide_out_left);
			}
		});

		LinearLayout myCollectLayout = (LinearLayout) findViewById(R.id.myCollectLayout);
		myCollectLayout.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				Intent myCollectIntent = new Intent();
				myCollectIntent.setClass(MainActivity.this,
						MyCollectActivity.class);
				startActivity(myCollectIntent);
				overridePendingTransition(R.anim.slide_in_left,
						R.anim.slide_out_left);
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		Log.d("TAG", "[MenuItem][getItemId]" + item.getItemId());
		switch (item.getItemId()) {
		case R.id.action_search:
			Intent searchIntent = new Intent();
			searchIntent.setClass(this, SearchActivity.class);
			startActivity(searchIntent);
			overridePendingTransition(R.anim.slide_in_left,
					R.anim.slide_out_left);
			break;
		case R.id.action_settings:
			Intent accountSettingIntent = new Intent();
			accountSettingIntent.setClass(this, AccountSettingActivity.class);
			startActivity(accountSettingIntent);
			overridePendingTransition(R.anim.slide_in_left,
					R.anim.slide_out_left);
			break;
		default:
			return super.onOptionsItemSelected(item);
		}
		return true;
	}

}
